home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / print / hpgl2ps.zip / CHANGESI.C next >
C/C++ Source or Header  |  1989-08-08  |  2KB  |  76 lines

  1. /* chagesizes.c
  2.  * This utility will take a string of real numbers seperated by commas and
  3.  * put them in an array. 
  4.  *
  5.  * Don McCormick 
  6.  */
  7. #include "defn.h"
  8.  
  9. #define ERROR1 "Only 9 line sizes allowed"
  10. #define ERROR2 "Too many decimal points in number"
  11. #define ERROR3 "line size specification incorrect"
  12. #define ERROR4 "Max no of characters for each line size is 5"
  13.  
  14. changesizes(sizebuf)
  15. char    sizebuf[50];
  16. {
  17.     int     i;
  18.     int     j = 0;
  19.     int     k = 0;
  20.     int     DECIMAL = 0;
  21.     float   number;
  22.     char    numbuf[5];
  23.  
  24.     for (i = 0; i < 50; i++)
  25.     {
  26.     if (sizebuf[i] == ',' || sizebuf[i] == NULL)
  27.     {
  28.         if ((number = atof(numbuf)) >= 0.01 && number <= 10)
  29.         pen_size[j] = number;    /* Put number in array */
  30.         else
  31.         fprintf(stderr, "Warning: line size too large ignored \n");
  32.  
  33.         if (sizebuf[i] == NULL) return;
  34.  
  35.         if (j++ > 8)
  36.         {
  37.         fprintf(stderr, "Error: %s\n", ERROR1);
  38.         exit(1);
  39.         }
  40.         for (k = 0; k < 5; k++)
  41.         numbuf[k] = NULL;    /* Clear number buffer */
  42.  
  43.         k = 0;
  44.         DECIMAL = 0;    /* One decimal per number */
  45.  
  46.         while (sizebuf[i + 1] == ',' && sizebuf[i + 1] != NULL)
  47.         i++;        /* Get rid of extra commas */
  48.     } else
  49.     {
  50.         if ((sizebuf[i] >= '0' && sizebuf[i] <= '9')
  51.         || sizebuf[i] == '.')
  52.         {
  53.         if (sizebuf[i] == '.')
  54.         {
  55.             if (DECIMAL == 1)
  56.             {
  57.                 fprintf(stderr, "Error: %s\n", ERROR2);
  58.                 exit(1);
  59.             }
  60.             DECIMAL = 1;
  61.         }
  62.         numbuf[k] = sizebuf[i];
  63.         } else
  64.         {
  65.         fprintf(stderr, "Error: %s\n", ERROR3);
  66.         exit(1);
  67.         }
  68.         if (k++ > 5)
  69.         {
  70.         fprintf(stderr, "Error: %s\n", ERROR4);
  71.         exit(1);
  72.         }
  73.     }
  74.     }
  75. }
  76.